package com.gin.kotlin.no_gay_alliance.adapter.user

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.databinding.ItemHeaderRecyclerviewBinding

/**
 * 用户信息中额外信息适配器
 */
class UserHeaderRecyclerViewAdapter(context: Context, handler: MyHandler, data: List<DataGroup> = listOf()) :
    AbstractBindingRecyclerViewAdapter<ItemHeaderRecyclerviewBinding, UserHeaderRecyclerViewAdapter.DataGroup>(context, handler, false, data.toMutableList()) {
    /**
     * 当显示某一位置的item时的操作
     * @param holder ViewHolder
     * @param position Int
     * @param b ViewBinding
     * @param dataModel 数据对象
     */
    override fun onBindViewHolder(holder: ViewHolder<ItemHeaderRecyclerviewBinding>, position: Int, b: ItemHeaderRecyclerviewBinding, dataModel: DataGroup) {
        b.tvHeader.text = dataModel.title
        b.recyclerView.adapter = dataModel.adapter
        b.recyclerView.layoutManager = dataModel.layoutManager ?: b.recyclerView.layoutManager
    }

    /**
     * 数据组
     * @property title String
     * @property adapter Adapter<*>
     * @constructor
     */
    data class DataGroup(
        val title: String,
        val adapter: RecyclerView.Adapter<*>,
        val layoutManager: RecyclerView.LayoutManager? = null,
    )
}